package com.tyc.kafka.consumer;

import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.common.serialization.StringDeserializer;

import java.time.Duration;
import java.util.ArrayList;
import java.util.Properties;

public class CustomConsumerGroup2 {
    public static void main(String[] args) {
        Properties properties = new Properties();
        properties.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "127.0.0.1:9092,127.0.0.1:9093");
        properties.setProperty(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
        properties.setProperty(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
        properties.setProperty(ConsumerConfig.GROUP_ID_CONFIG, "group_test_1");
        KafkaConsumer kafkaConsumer = new KafkaConsumer<String,String>(properties);
        ArrayList<String> topics = new ArrayList<>();
        topics.add("test0");
        kafkaConsumer.subscribe(topics);
        while (true){
            ConsumerRecords consumerRecords = kafkaConsumer.poll(1000);
            for (Object consumerRecord : consumerRecords) {
                System.out.println(consumerRecord);
            }
        }
    }
}
